package com.huaiwei.usmManager.modules.usm.controller;

import com.huaiwei.usmManager.common.utils.R;
import com.huaiwei.usmManager.modules.usm.entity.ReportedLossEntity;
import com.huaiwei.usmManager.modules.usm.service.ReportedLossService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/*
  添加报损
  修改报损
  删除报损
  商品报损列表
  商品报损列表筛选
 */

@RestController
@RequestMapping("/loss")
@Api(tags = "商品报损模块")
public class ReportedLossController {

  @Autowired
  private ReportedLossService reportedLossService;

  @GetMapping("/list")
  @ApiOperation("分页查询商品报损列表")
  public R list(@RequestParam Map<String, Object> params) {
    return R.ok().put("page", reportedLossService.queryPage(params));
  }

  @GetMapping("/info/{lossId}")
  @ApiOperation("查询报损详情")
  public R info(@PathVariable("lossId") Integer lossId) {
    return R.ok().put("data", reportedLossService.getInfoById(lossId));
  }

  @PostMapping("/update")
  @ApiOperation("添加或修改商品报损")
  public R update(@RequestBody ReportedLossEntity reportedLoss) {
    reportedLossService.insertOrUpdate(reportedLoss);
    return R.ok();
  }

  @DeleteMapping("/delete/{lossId}")
  @ApiOperation("删除报损")
  public R delete(@PathVariable("lossId") Integer lossId) {
    reportedLossService.deleteInfo(lossId);
    return R.ok();
  }

  @PostMapping("/status")
  @ApiOperation("修改报损状态")
  public R status(@RequestBody ReportedLossEntity reportedLoss) {
    reportedLossService.updateById(reportedLoss);
    return R.ok();
  }

  @GetMapping("/images/list/{lossId}")
  @ApiOperation("报损关联图片列表")
  public R imagesList(@PathVariable("lossId") Integer lossId) {
    return R.ok().put("data", reportedLossService.getImageListByLossId(lossId));
  }


}
